﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using digit.Core;
using SMS.ServiceManager;
using SMS.Helper;
using SMS.Charts;
using SMS.UserManager;

public partial class Modules_ListStatErrorMsg : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ClientState.MemberInfo.UserType == 0)
        {

        }
        else
            Response.Redirect("Default.aspx?module=Warning");
    }

    protected void btnStat_Click(object sender, EventArgs e)
    {
        this.BindStat("BET_KQ");
    }

    protected void BindStat(string ServiceID)
    {
        try
        {
            FusionLineChart lineChart = new FusionLineChart();

            lineChart.caption = "Thống kê tin sửa lỗi " + ServiceID.ToUpper();

            string chartHtml = lineChart.CreateSetElement(BuildData(ddlMember.SelectedValue), FusionLineChart.Line2D, divLineChart.ClientID, false, "", "name", "value", "text", "id", "#", true, 800, 600);
            divLineChart.InnerHtml = chartHtml;
        }
        catch { }
    }

    private DataTable BuildData(string userName)
    {
        DataTable dt = null;

        if (userName != "")
        {
            dt = MessageInManager.StatisticMsgInError_ByEdit(ClientState.MemberInfo.Username);

            if (dt != null && dt.Rows.Count > 0)
            {
                DataTable dtData = new DataTable();

                dtData.Columns.Add("name");
                dtData.Columns.Add("value");
                dtData.Columns.Add("text");
                dtData.Columns.Add("id");

                DataRow drData = null;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    drData = dtData.NewRow();

                    drData["name"] = dt.Rows[i]["RequestTime"].ToString();
                    drData["value"] = dt.Rows[i]["RowNo"].ToString();
                    drData["text"] = "Tổng số tin : " + dt.Rows[i]["RowNo"].ToString();
                    drData["id"] = "";

                    dtData.Rows.Add(drData);
                }

                return dtData;
            }
            else
            {
                this.lblError.Text = "Hiện tại chưa có số liệu thống kê tin sửa lỗi.";
                return null;
            }
        }
        return null;
    }
}
